home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / eclsycon / traydemo.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-05-20  |  8.5 KB  |  234 lines

  1. VERSION 5.00
  2. Object = "{80FA4117-F062-11D1-B462-0020AF33A8E7}#1.0#0"; "ECLTRAY.OCX"
  3. Begin VB.Form Form1 
  4.    Caption         =   "Demo using ECLTray Control"
  5.    ClientHeight    =   1356
  6.    ClientLeft      =   48
  7.    ClientTop       =   336
  8.    ClientWidth     =   5100
  9.    LinkTopic       =   "Form1"
  10.    LockControls    =   -1  'True
  11.    MaxButton       =   0   'False
  12.    ScaleHeight     =   1356
  13.    ScaleWidth      =   5100
  14.    ShowInTaskbar   =   0   'False
  15.    StartUpPosition =   2  'CenterScreen
  16.    Begin ECLTrayIcon.Ecltray Ecltray1 
  17.       Left            =   96
  18.       Top             =   1248
  19.       _ExtentX        =   804
  20.       _ExtentY        =   529
  21.       TrayIcon        =   "TrayDemo.frx":0000
  22.       IconToolTip     =   "ECLIPSE
  23.  System Tray Icon"
  24.    End
  25.    Begin VB.CommandButton Command4 
  26.       Caption         =   "E&xit"
  27.       Height          =   320
  28.       Left            =   3504
  29.       TabIndex        =   4
  30.       Top             =   850
  31.       Width           =   1500
  32.    End
  33.    Begin VB.CommandButton Command3 
  34.       Caption         =   "&Cycle Icon"
  35.       Height          =   320
  36.       Left            =   1800
  37.       TabIndex        =   3
  38.       Top             =   850
  39.       Width           =   1500
  40.    End
  41.    Begin VB.CommandButton Command2 
  42.       Caption         =   "Hide &Icon"
  43.       Height          =   320
  44.       Left            =   100
  45.       TabIndex        =   2
  46.       Top             =   850
  47.       Width           =   1500
  48.    End
  49.    Begin VB.CommandButton Command1 
  50.       Caption         =   "Change &Tip"
  51.       Height          =   320
  52.       Left            =   144
  53.       TabIndex        =   1
  54.       Top             =   144
  55.       Width           =   1500
  56.    End
  57.    Begin VB.TextBox Text1 
  58.       Height          =   300
  59.       Left            =   1944
  60.       MaxLength       =   64
  61.       TabIndex        =   0
  62.       Text            =   "Text1"
  63.       Top             =   170
  64.       Width           =   2940
  65.    End
  66.    Begin VB.Image Image1 
  67.       Height          =   384
  68.       Index           =   3
  69.       Left            =   2400
  70.       Picture         =   "TrayDemo.frx":059A
  71.       Stretch         =   -1  'True
  72.       ToolTipText     =   "My Computer"
  73.       Top             =   1272
  74.       Visible         =   0   'False
  75.       Width           =   384
  76.    End
  77.    Begin VB.Image Image1 
  78.       Height          =   384
  79.       Index           =   2
  80.       Left            =   1968
  81.       Picture         =   "TrayDemo.frx":0E64
  82.       Stretch         =   -1  'True
  83.       ToolTipText     =   "The Globe"
  84.       Top             =   1272
  85.       Visible         =   0   'False
  86.       Width           =   384
  87.    End
  88.    Begin VB.Image Image1 
  89.       Height          =   384
  90.       Index           =   1
  91.       Left            =   1416
  92.       Picture         =   "TrayDemo.frx":116E
  93.       Stretch         =   -1  'True
  94.       ToolTipText     =   "Windows Explorer"
  95.       Top             =   1272
  96.       Visible         =   0   'False
  97.       Width           =   384
  98.    End
  99.    Begin VB.Image Image1 
  100.       Height          =   384
  101.       Index           =   0
  102.       Left            =   888
  103.       Picture         =   "TrayDemo.frx":1A38
  104.       Stretch         =   -1  'True
  105.       ToolTipText     =   "Internet Explorer"
  106.       Top             =   1272
  107.       Visible         =   0   'False
  108.       Width           =   384
  109.    End
  110.    Begin VB.Menu mnuMenu 
  111.       Caption         =   "Menu"
  112.       Visible         =   0   'False
  113.       Begin VB.Menu mnuRestore 
  114.          Caption         =   "&Restore"
  115.       End
  116.       Begin VB.Menu mnuMinimize 
  117.          Caption         =   "Mi&nimize"
  118.       End
  119.       Begin VB.Menu mnuExit 
  120.          Caption         =   "E&xit"
  121.       End
  122.    End
  123. Attribute VB_Name = "Form1"
  124. Attribute VB_GlobalNameSpace = False
  125. Attribute VB_Creatable = False
  126. Attribute VB_PredeclaredId = True
  127. Attribute VB_Exposed = False
  128. Option Explicit
  129. ' This declares should be in a module but I want to keep the code in a single file
  130. Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
  131. Private Declare Sub PostQuitMessage Lib "user32" (ByVal nExitCode As Long)
  132. Dim OldIcon As StdPicture
  133. Dim OldToolTip As String
  134. Dim IconId As Integer
  135. Private Sub Command1_Click()
  136.      Ecltray1.IconToolTip = Text1.Text
  137. End Sub
  138. Private Sub Command2_Click()
  139.     With Ecltray1
  140.         If .ShowIcon Then
  141.             Command2.Caption = "Show &Icon"
  142.             .ShowIcon = False
  143.         Else
  144.             Command2.Caption = "Hide &Icon"
  145.             .ShowIcon = True
  146.         End If
  147.     End With
  148.      
  149. End Sub
  150. Private Sub Command3_Click()
  151.     If IconId > 4 Then IconId = 0                       'maximum number of Icon that we have
  152.     Select Case IconId
  153.     Case 0:
  154.             Set Ecltray1.TrayIcon = OldIcon         'Control's Stored Icon
  155.             Ecltray1.IconToolTip = OldToolTip       'control's stored ToolTip
  156.             Text1.Text = OldToolTip
  157.     Case 1 To 4:
  158.             Set Ecltray1.TrayIcon = Image1(IconId - 1).Picture ' copy the Image stored in Image1 -must be an Icon!
  159.             Ecltray1.IconToolTip = Image1(IconId - 1).ToolTipText   ' copy the ToolTipText of Image1. This can be set to anything
  160.             Text1.Text = Image1(IconId - 1).ToolTipText
  161.     End Select
  162.     IconId = IconId + 1
  163. End Sub
  164. Private Sub Command4_Click()
  165.     mnuExit_Click
  166. End Sub
  167. Private Sub Ecltray1_DblClick(Button As Integer)
  168.     If WindowState = 0 Then             'I tried to use 'If Not WindowState' but the Else part wouldn't trigger. I don't know why.
  169.         WindowState = vbMinimized       ' minimize the form
  170.     Else
  171.         WindowState = vbNormal          ' limit the viewable state to normal
  172.         SetForegroundWindow (Me.hwnd)   'Ensure the form is visible and has the  focus
  173.     End If
  174. End Sub
  175. Private Sub ecltray1_MouseUp(Button As Integer, shift As Integer, X As Single, Y As Single)
  176. ' Button can be 1(Left); 2(Right) or 4(Middle)
  177. ' Shift can be 1(Shiftkey is down), 2(ControlKey is down) and 4 (AltKey is Down)
  178. ' Note that value of shift can be one or combination of the three keys.i.e. 6=(Ctrl and Alt keys as pressed)
  179. ' The value of X and Y indicates the location of the mouse cursor
  180.      
  181.     If Button = 2 Then                              ' Execute only when the right Mouse Button is pressed and release
  182.         SetForegroundWindow (Me.hwnd)               'Activate form1
  183.         PopupMenu mnuMenu, vbPopupMenuRightAlign    'pops up the menu we created 'mnuMenu'
  184.     End If
  185.      
  186. End Sub
  187. Private Sub Form_Load()
  188.     Set OldIcon = Ecltray1.TrayIcon                 'copy the control's stored Icon & ToolTipText
  189.     OldToolTip = Ecltray1.IconToolTip
  190.     Text1.Text = OldToolTip
  191.     IconId = 1                                      'set the next icon to be displayed when the Cycle Icon button is pressed
  192.      
  193. End Sub
  194. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  195.     Set Form1 = Nothing
  196. End Sub
  197. Private Sub Form_Resize()
  198.     If WindowState Then
  199.         mnuMinimize.Enabled = False
  200.         mnuRestore.Enabled = True
  201.     Else
  202.         mnuMinimize.Enabled = True
  203.         mnuRestore.Enabled = False
  204.     End If
  205.      
  206. End Sub
  207. Private Sub mnuExit_Click()
  208. ' ***************************************************************
  209. ' NOTE: Quiting the program from the system Icon (popupmenu) by
  210. '       means of 'Unload Form1' statement will generate an 'Invalid
  211. '       Page Fault in Module <unknown>' message. This will happen
  212. '       only when you try to exit the program using the System Icon.
  213. '       I still don't know why this happen. To work around this
  214. '       problem I used an API call to quit the program properly
  215. '       'Postquitmessage (nExitCode as Long)'. There is one  problem
  216. '       with it, however. if you remove the code 'X = MsgBox...', the
  217. '       Exit code will be ignored and the program will continue running.
  218. '       So, the MsgBox is necessary to shut the program. Again, I still
  219. '       don't know why this happen. Please send me some information if
  220. '       you know how to work around these problems, because I'm still
  221. '       searching for an explanation.
  222. ' *****************************************************************
  223. Dim X As Integer
  224.     X = MsgBox("Are you sure You want to quit", vbYesNo Or vbQuestion)
  225.     If X = vbNo Then Exit Sub
  226.     PostQuitMessage vbFormCode
  227. End Sub
  228. Private Sub mnuMinimize_Click()
  229.     WindowState = 1         'minimize
  230. End Sub
  231. Private Sub mnuRestore_Click()
  232.     WindowState = 0         'Normal/Restore
  233. End Sub
  234.